import * as echarts from '../../ec-canvas/echarts';

let chart = null;

function initChart(canvas, width, height) {
  chart = echarts.init(canvas, null, {
    width: width,
    height: height
  });
  canvas.setChart(chart);

  

  var option = {
    color: ['#37a2da', '#67e0e3'],
    tooltip: {
      trigger: 'axis',
    },
    legend: {
      data: ['低压', '高压']
    },
    grid: {
      left: 15,
      right: 30,
      bottom: 15,
      top: 40,
      containLabel: true
    },
    xAxis: {
      type: 'category',
      boundaryGap: false,
      data: ['2018-5-1', '2018-5-2', '2018-5-3', '2018-5-4', '2018-5-5']
    },
    yAxis: {
      type: 'value',
      max: function (value) {
        return (parseInt(value.max / 50) + 1) * 50;
      },
      min: function (value){
        return(parseInt(value.min / 50) - 1) * 50;
      }
    },
    series: [
      {
        name: '低压',
        type: 'line',
        data: [80, 78, 80, 80, 80]
      },
      {
        name: '高压',
        type: 'line',
        data: [120, 130, 120, 168, 120, 120]
      }
    ]
  };

  chart.setOption(option);
  return chart;
}

Page({
  onShareAppMessage: function (res) {
    return {
      title: '这是我的血压历史',
      path: '/pages/history/history',
      success: function () { },
      fail: function () { }
    }
  },
  data: {
    ec: {
      onInit: initChart
    }
  },

  onReady() {
    /*
    setTimeout(function () {
      // 获取 chart 实例的方式
      console.log(chart)
    }, 2000);*/
  }
});
